package cn.hc.sp02.item.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import sp01.pojo.Item;
import sp01.service.ItemService;
import web.util.JsonResult;

import java.util.List;

/**
 * @author 海绵宝宝
 * date 2021/10/29 23:12
 */
@Slf4j
@RestController
public class ItemController {
    @Autowired
    private ItemService itemService;
    @Value("${server.port}")
    private int prot;

    //获取商品列表
    @GetMapping("/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId){
        List<Item> items = itemService.getItems(orderId);
        return JsonResult.ok().msg("port:"+prot).data(items);
    }
    //减少商品库存
    @PostMapping("/decreaseNumber")
    public JsonResult<?> decreaseNumber(@RequestBody List<Item> items){
        itemService.decreaseNumber(items);
        return JsonResult.ok().msg("减少商品库存成功");
    }
}
